def tria(n):
    for i in range(1, n + 1):
        line = ''
        for j in range(i , 0, -1):
            line += "{:>{}}".format(j, len(str(j)) + 1)
        print("{:>{}}".format(line,  27))
tria(12)

def tria1(n):
    for i in range(1, n + 1):
        line = ''
        for j in (range(1, n - i + 2))[::-1]:
            line += "{:>{}}".format(j, len(str(j)) + 1)
        print("{:>27}".format(line)) # 这里的长度写死了, 如果打印20个数这个长度又不满足了
tria1(12)

